﻿#ifndef CLIENTTHREAD_H
#define CLIENTTHREAD_H

#include <QThread>
#include "../utils/datamanager.h"
#include "../utils/groupitemdata.h"

class QTcpSocket;
class ClientThread : public QThread
{
    Q_OBJECT
public:
    enum PutWeighType{
        PW_weigh    =   1,
        PW_putIn,
        PW_putWeigh,//both opt:weigh and put it.
        PW_none,
    };


//    explicit ClientThread(int groupid = 0/*GroupNum*/,QString groupip = "",PutWeighType type = PW_putWeigh,QObject *parent = 0);
    explicit ClientThread(PutWeighType type = PW_putWeigh,QObject *parent = 0);
    explicit ClientThread(QString firstTb,PutWeighType type = PW_putWeigh,QObject *parent = 0);

    void run();

    void setDefaultValue(int groupid,QString groupip);//{m_groupid = groupid;m_groupip = groupip;}

    void setData(GroupItemData data);

signals:
    void sig_finishedPutWeigh(QString,QMap<QString,QString>);//餐数,称量值(map)
    void sendGroupPutWeithInfo(int,send_head);//发送称量信息-以得到返回称量并进行UI交互

    void sig_UpdateState(GroupItemData,BatchFeed::ClientConnectType,QString/*errString*/);
public slots:
    void slt_connecttoServer();
    void slt_getDateFromServer();
private:
    int m_groupid;
    QString m_groupip;
    QString m_dbFilename;
    QString m_CurrentTb;
//	QTcpSocket *socket;
    quint16 GetCheckSum (void *data, quint16 len);
    bool checkData(QByteArray byte,quint32 checkvalue);

    PutWeighType m_type;
    GroupItemData m_data;

    QStringList strlist_boxnum;
    QHash<QString,QString> m_mapvalue;
    QMap<QString,QString> m_mapPutvalue;

    QMutex m_mutex;
};

#endif // CLIENTTHREAD_H
